const env = require('./env')
process.env.MODE = process.env.MODE || 'development'

export default {
    // Global page headers: https://go.nuxtjs.dev/config-head\
    mode: 'universal',
    server: {
        port: 3000, // default 3000
        host: '0.0.0.0'
    },
    head: {
        title: process.env.npm_package_name || '统一标题', // 统一标题
        meta: [
            {
                charset: 'utf-8'
            }, {
                name: 'viewport',
                content: 'width=device-width, initial-scale=1'
            }, { // 移动端
                hid: 'description',
                name: 'description',
                content: '自定义描述信息'
            }, {
                name: 'format-detection',
                content: 'telephone=no'
            }
        ],
        // script:[
        // {src:'http://code.jquery.com/jquery-latest.js'}
        // ],
        link: [
            {
                rel: 'icon',
                type: 'image/x-icon',
                href: '/favicon.ico'
            }, {
                rel: 'stylesheet',
                href: 'http://fonts.useso.com/css?family=Ubuntu'
            }
        ]
    },
    router: {
        middleware: 'auth',
        // 跳转路由回到顶部
        scrollBehavior(to, from, savedPosition) {
            return {x: 0, y: 0}
        },
        // 扩展路由
        extendRoutes(routes, resolve) {
            console.log(routes);
            routes.push({
                name: 'home',
                path: '/index',
                component: resolve(__dirname, 'pages/index.vue')
            })
        }
    },

    // 定义系统默认loading效果，或者指定loading组件
    loading: '~/components/loading.vue',

    // Global CSS: https://go.nuxtjs.dev/config-css
    css: [
        'assets/css/base.css', 'assets/css/transition.css', 'element-ui/lib/theme-chalk/index.css'
    ],

    // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
    plugins: [
        '~/plugins/router', {
            src: '~/plugins/axios',
            ssr: true // 服务端
        }, {
            src: '~/plugins/element-ui',
            ssr: true,
            // 不支持ssr 只会在客户端渲染选择false
            // mode:'server' //clien //v2.4+
        },
        '~/plugins/mixins'
    ],

    // Auto import components: https://go.nuxtjs.dev/config-components
    components: true,

    // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
    buildModules: ['@nuxt/typescript-build','@nuxt/postcss8'],

    // Modules: https://go.nuxtjs.dev/config-modules
    modules: [
        '@nuxtjs/axios', 'cookie-universal-nuxt', '@nuxtjs/style-resources'
    ],
    styleResources: {
        scss: ['./assets/scss/global.scss']
    },
    axios: { // 国脉
        baseURL: env[process.env.MODE].BASE_URL,
        // 预发布环境地址
        // browserBaseURL: '/api', // 客户端调用时的地址
        prefix: '/api',
        proxy: true
    },

    proxy: {
        '/api/': {
            target: env[process.env.MODE].BASE_URL, // 代理转发地址
            changeOrigin: true,
            pathRewrite: {
                "^/api/": "/"
            }
        }
    },
    env: {
        ... env[process.env.MODE]
    },
    // Build Configuration: https://go.nuxtjs.dev/config-build
    build: {
        transpile: [/^element-ui/]
    }
}
